from GoBang import GoBang_Train
import json
def train(epoch=500, path='model.json'):
    game = GoBang_Train(3)
    game.train(epoch)
    with open('model/model.json', 'w') as f:
        json.dump(game.q, f)  # 会在目录下生成一个1.json的文件，文件内容是dict数据转成的json数据
        f.close()
    print(f"{epoch}轮训练以完成！模型保存在{path}这一文件中。请调用play函数进行愉快的玩耍！")


def play(path='model/model.json'):
    try:
        f = open(path, 'r')
        game = GoBang_Train(3, json.load(fp=f))
        game.play()
    except Exception as e:
        print(e.args[1])


if __name__ == "__main__":
    play("model/model.json")